<template>
  <div class="big-B&B">
    <div class="container">
      <div class="header">
        <div class="header-left">
          <div class="left-title">推荐民宿</div>
          <div
            class="introduce-city"
            v-for="(cityItem, index) in BBCityList"
            :key="cityItem.index"
          >
            <em @mouseenter="getBBDetailReq(cityItem.cityId, index)">{{
              cityItem.cityName
            }}</em>
            <div :class="showIcon === index ? 'introduce-bottom' : ''"></div>
          </div>
        </div>
        <router-link to="/access" class="header-right">
          <div class="right-text">全部</div>
          <i class="iconfont icon-youjiantou"></i>
        </router-link>
      </div>
      <div class="content">
        <div
          class="single-content"
          v-for="BBDetailItem in BBDetail"
          :key="BBDetailItem.index"
        >
          <img :src="BBDetailItem.coverImage" alt="" />
          <div class="single-text">
            <div class="single-text-top">{{ BBDetailItem.title }}</div>
            <div class="single-text-bottom">
              整套1居室·可住2人 |{{ BBDetailItem.locationArea }}
            </div>
          </div>
          <div class="price">
            ￥<em>{{ BBDetailItem.price }}</em>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "B&B",
};
</script>

<script setup>
import { getBBCity, getBBDetail } from "../../api/outFood/index";
import { onMounted, ref } from "vue";
const BBCityList = ref([]);
const BBDetail = ref([]);
let showIcon = ref(0);
onMounted(async () => {
  const result = await getBBCity();
  BBCityList.value = result.cityList;
  const res = await getBBDetail(BBCityList?.value[0].cityId);
  BBDetail.value = res.productList;
});

const getBBDetailReq = async (cityId, index = 0) => {
  const result = await getBBDetail(cityId);
  console.log(result);
  BBDetail.value = result.productList;
  showIcon.value = index;
};

// const changeDefaultBottomIcon = (cityItem) => {
//   this.BBCityList.forEach((item) => {
//     item.index = "0";
//   });
//   cityItem.index = "1";
// };
</script>

<style scoped>
* {
  margin: 0 auto;
}
.container {
  width: 1190px;
}
.header {
  width: 1190px;
  height: 45px;
  background-color: #f3bd48;
  border: 1px solid transparent;
  border-radius: 6px 6px 0 0;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  position: relative;
}
.header-left {
  margin-left: 18px;
  display: flex;
  position: absolute;
  left: 0;
}
.left-title {
  font-size: 17px;
  font-weight: 540;
  margin-right: 22px;
  height: 45px;
  line-height: 45px;
}
.introduce-city {
  font-size: 14px;
  margin-right: 12px;
  height: 45px;
  line-height: 45px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

.introduce-bottom {
  height: 0;
  width: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid #f8f8f8;
  position: absolute;
  bottom: -2px;
}

.header-right {
  position: absolute;
  right: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.right-text {
  font-size: 15px;
}
.introduce-city-text {
  padding-bottom: 10px;
}
.header-right .icon-youjiantou {
  font-size: 10px;
}
.content {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
}
.single-content {
  margin-bottom: 24px;
}
.single-content img {
  width: 392px;
  height: 208px;
  border-radius: 7px;
}
.single-text {
  padding-top: 16px;
  width: 390px;
}
.single-text-top {
  font-size: 16px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.single-text-bottom {
  color: #9999a6;
  padding: 9px 0;
}
.price {
  color: #ff6600;
  font-size: 16px;
}
.price em {
  font-size: 22px;
  font-weight: 540;
}
</style>